<?php echo $this->render($this->includeDir . '/toolbar.php');?>
<?php echo $this->flashMessage();?>
<?php 
	$arrParam = $this->arrParam;
	
	$name 		= $this->formText('name',$this->Item['name'],array('class'=>'width-300 bg-green2 floatLeft' ));
	//$name 		.= $this->cmsError('name');
	$parentValue = $this->Item['parents']>0?$this->Item['parents']:1;
	$parents	= $this->cmsSelect('parents', $parentValue,array('class'=>'width-150','size'=>10), $this->slbParents);
	
	$options 	= array('group'=>' Group type ','root'=>' Root type');	
	$type 		= $this->formSelect('type',$this->Item['type'],array('class'=>'width-150'),$options);	
	
	$priority 	= $this->formText('priority',$this->Item['priority'],array('class'=>'width-100 floatLeft'));
	
	$avatar		= $this->formFile('avatar',array('class'=>'floatLeft' ));
	
	$ranking	= $this->formFile('ranking',array('class'=>'floatLeft' ));
	
	$group_acp 	= $this->formSelect('group_acp',$this->Item['group_acp'],array('class'=>'width-150'),array($this->translate('No'), $this->translate('Yes')), ' ');
	
	$group_default = $this->formSelect('group_default',$this->Item['group_default'],array('class'=>'width-150'),array($this->translate('No'), $this->translate('Yes')), ' ');
	
	$ordering	= $this->formText('ordering',$this->Item['ordering'],array('class'=>'width-100 floatLeft'));
	
	$options 	= array('inactive'=>$this->translate('Inactive'),'active'=>$this->translate('Active'));	
	$status 	= $this->formSelect('status',$this->Item['status'],array('class'=>'width-150'),$options);
	
	$formHelp = '';
	$arrTooltip = array(
						'name'=>"Name of group.( Ex: Customer, Vip member, ...)",
						'parents'=>"Parents of group.( Ex: Customer, Vip member, ...)",
						'priority'=>"This will affect the rights of member group in the system.( Ex: 3,4,5...)",
						'avatar'=>"Default avatar of group.|1. Files can be uploaded to the extension: png, jpg, gif|2. File size is not larger than 50KB",
						'ranking'=>"Default ranking of group.|1. Files can be uploaded to the extension: png, jpg, gif|2. File size is not larger than 50KB",
						'group_acp'=>'If the value is "No", this group is not allowed to access the "Admin Cpanel".',
						'group_default'=>'The group has the value "No", it can be deleted by the administrator',
						'ordering'=>'Ordering of group ( Ex:1, 5, 10 ...)|You can be left blank',
						'status'=>'Status of group',
						);
	if(count($arrTooltip)>0){
		foreach ($arrTooltip as $key => $val){
			$formHelp  .= $this->cmsFormHelp('.form-table #' . $key, $this->translate($val));	
		}
	}
	
	/*=======================================================
	 * Start - Hiển thị các thông báo error của Form 
	 *=======================================================*/	
		
	 if(count($this->errors)>0){	
	 	foreach ($this->errors as $key => $val){	 		
	 		$$key .= $this->cmsError($key,$val);	
	 		$selector = '.form-table #' . $key . '-error';
	 		$options = array('type'=>'error','name'=>'#' .$key);
	 		$formHelp  .= $this->cmsFormHelp($selector, $this->translate($val),null,$options);
	 		
	 	}
	 }

	 if($this->arrParam['action'] == 'edit'){
	 	$config = new Zendvn_Controller_Config(array('module'=>$arrParam['module'],
												'fileConfig'=>'user-group.ini'));
	 	
	 	$avatarConfig = $config->getConfig('avatar');
		
		$current_avatar = '<div id="load-content-avatar" class="clr width-150 center">';
		if(!empty($this->Item['avatar'])){
			$avatarUrl = $avatarConfig['thumbUrl'] . '/' . $this->Item['avatar'];
			$removeLink = $this->url(array('action'=>'remove-pic','type'=>'avatar','file'=>$this->Item['avatar']));
			$current_avatar .= '<br>' . $this->cmsImage('avatar',$avatarUrl,array('width'=>'75px'))
							. '<br><a  class="remove" href="javascript:loadPage(\'div#load-content-avatar\',\'' . $removeLink . '\')">remove</a>';
		}
		
		$current_avatar .= $this->formHidden('current_avatar',$this->Item['avatar'])
						. '</div>';
		$avatar .=	$current_avatar;	
		
		
		$rankingConfig = $config->getConfig('ranking');
		
		$current_ranking = '<div id="load-content-ranking" class="clr width-150 center">';
		if(!empty($this->Item['ranking'])){
			$rankingUrl = $rankingConfig['uploadUrl'] . '/' . $this->Item['ranking'];
			$removeLink = $this->url(array('action'=>'remove-pic','type'=>'ranking','file'=>$this->Item['ranking']));
			$current_ranking .= '<br>' . $this->cmsImage('ranking',$rankingUrl,array('width'=>'75px'))
							. '<br><a class="remove" href="javascript:loadPage(\'div#load-content-ranking\',\'' . $removeLink . '\')">remove</a>';
		}
		
		$current_ranking .= $this->formHidden('current_ranking',$this->Item['ranking'])
						. '</div>';
		$ranking .=	$current_ranking;	
		
	}
	
	 $arrRow = array(
						array('label'=>$this->translate('Tên nhóm'),'input'=>$name),						
						array('label'=>$this->translate('Danh mục cha'),'input'=>$parents),						
						array('label'=>$this->translate('Độ ưu tiên'),'input'=>$priority),
						array('label'=>$this->translate('Ảnh đại diện'),'input'=>$avatar),
						array('label'=>$this->translate('Ranking'),'input'=>$ranking),
						array('label'=>$this->translate('Quyền admin'),'input'=>$group_acp),
						array('label'=>$this->translate('Nhóm mặc định'),'input'=>$group_default),
						array('label'=>$this->translate('Trạng thái'),'input'=>$status),
						array('label'=>$this->translate('Xắp xếp'),'input'=>$ordering),
	
					 );
	$tdForm = $this->partialLoop('row.php',$arrRow);
?>

<script type="text/javascript">
	$(document).ready(function() {
		<?php echo $formHelp;?>
	});
</script>
<div id="element-box">
	<div class="m">
		<div class="form-table">
            	<fieldset class="admin-fieldset">
                <legend class="admin-legend"><?php echo $this->translate('Form Detail')?></legend>
            	<table width="100%" border="0">
                	<?php echo $tdForm;?>
                </table>
                <div class="clr"></div>
                </fieldset>             
            </div>
            <div class="clr"></div>
	</div>
</div>
